#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Description : 处理接口返回的json数据

# from jmespath import search
import jmespath as jp


def jmespath(expression, data, options=None):
    """
    jmespath search data
    https://github.com/jmespath/jmespath.py
    """
    return jp.search(expression, data, options)


if __name__ == '__main__':

    expression = '**.token'
    data1 = {'code': 200, 'msg': 'success', 'data': {'auth_type': 'header', 'ddns': ['yaotiejun.net.cn'], 'deny_change_pwd': False, 'edev': False, 'enable_change_pwd': False, 'enable_otp': False, 'http_port': 9999, 'https_port': 9443, 'ipv4': ['172.17.20.42', '192.100.1.1', '192.100.2.1', '192.100.0.1', '172.18.0.1'], 'ipv6': ['2222:db8:85a3::101', '2222:db8:85a3::201', '2222:db8:85a3::1'], 'is_bootstrap_completed': True, 'is_cloud': False, 'is_domain': False, 'is_exceed': False, 'is_simple': False, 'match_rule': True, 'mobile_guide': False, 'model': 'DXP8800 Pro', 'nas_name': 'DXP8800PRO-A6F1', 'public_key': 'LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJJakFOQmdrcWhraUc5dzBCQVFFRkFBT0NBUThBTUlJQkNnS0NBUUVBcGZBVFAwbTFYRUEzTHc3K05qK0IKcERBb0c5ZVNaOGFWZGlQQzZneGNWbE50ck1PQmhNdHBrczJzSUJhb0lNQ2NVR3NGRGZoMUNDVkduR2ludVB1eApTdGlvUU5FRVJIUHBWNmdiS1E5WGFxakdPWkFPU1Y2eGtMMkZFMS9KR3o5ZE9ocG5GWDhGSmgyYVdQL2xSbzFXClp1MGJJMkxvdXBWbGtBVjV0aURCTDFUZnRoZWt5UzV5TDNpcktna1NSUlpHU1dpYzNpVkUrQ1Y4MHo4U3hYRGcKNkZYSFFoRGlmK1NWaGw3d1MxM0liZ2h3T09xL2hMYlpMODZ1dlVhY0ZJVlRUL2dmM01OVWVmaVVUcUxDdEFBegp1eTd6SVlKYnJaeExtY3pwYkxCWG1DOXF2UklrTzNzY3R6M1NxaXZhMVVBMHhLWG9ZZlFXeWNRYmhaYm1vdjdFClBRSURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K', 'role': 'admin', 'sn': 'UG756JJ02240A6F1', 'static_token': '7b72d49ca8f0d92a2ad0dcf0737c53a7', 'system_version': '1.0.0.1917', 'token': '0E8BAA2884034FC0B5C893AF914B6163', 'token_id': '200e4116e73c0ae5ef88e013bf041c69', 'uglink': 'wang123.cn-test.ug.link:8088', 'uglink_id': 'wang123', 'uid': 1001, 'urgent_email': '', 'username': 'test3', 'version_number': 100001917}, 'time': 0.071730797}
    print(jmespath(expression, data1))